#include "DynamicArray.h"
#include <ctime>

class Student
{
public:
    Student(int id,std::string name):id(id),name(name){}
    // Student(const Student& s)
    // {
    //     id = s.id;
    //     name = s.name;
    // }
    // Student& operator=(const Student& s)
    // {
    //     id = s.id;
    //     name = s.name;
    //     return *this;
    // }
    friend void Print(ElementType element);
    friend int Compare(ElementType element1 ,ElementType element2);
    friend void Free(ElementType element);
    friend bool Compare1(ElementType element1 ,ElementType element2);
private:
    int id;
    std::string name;
};

    void Free(ElementType element)
    {
        Student *stu = (Student *)element;
        free(stu);
    }
    int Compare(ElementType element1 ,ElementType element2)
    {
        Student *stu1 = (Student *)element1;
        Student *stu2 = (Student *)element2;
        return stu1->id - stu2->id;
    }
   
    void Print(ElementType element)
    {
        Student *stu = (Student *)element;
        std::cout<<stu->id<<" "<<stu->name<<std::endl;
    }
    bool Compare1(ElementType element1 ,ElementType element2)
    {
        Student *stu1 = (Student *)element1;
        Student *stu2 = (Student *)element2;
        return ((stu1->id == stu2->id) && (stu1->name == stu2->name));
    }

int main()
{   
    DynamicArray a;
    a.SetPrint(Print);
    a.SetCompare(Compare);
    a.SetFree(Free);
    a.SetComepare1(Compare1);
    Student *stu1 = new Student(4,"Ddd");
    Student *stu3 = new Student(3,"Ccc");
    Student *stu5 = new Student(6,"Eee");
    Student *stu7 = new Student(7,"Ggg");
    Student *stu9 = new Student(2,"Bbb");   
    //Student stu6(7,"yefan");     
    
    // DynamicArray b;
    // b.SetPrint(Print);
    // b.SetCompare(Compare);
    // b.SetFree(Free);
    // b.SetComepare1(Compare1);

    // Student *stu2 = new Student(3,"Ccc");
    // Student *stu4 = new Student(6,"Eee");
    // Student *stu6 = new Student(6,"Fff");
    // Student *stu8 = new Student(8,"Hhh");
    // Student *stu10 = new Student(10,"Jjj"); 

    DynamicArray c;
    c.SetPrint(Print);
    c.SetCompare(Compare);
    c.SetFree(Free);

    a.InsertTail(stu1);
    a.InsertTail(stu3);
    a.InsertTail(stu5);
    a.InsertTail(stu7); 
    a.InsertTail(stu9); 

    // b.InsertTail(stu2);
    // b.InsertTail(stu4);
    // b.InsertTail(stu6);
    // b.InsertTail(stu8); 
    // b.InsertTail(stu10);  
    a.Sort();
    a.show();
    //b.show();
    // DynamicArray p = a.FindByElement((ElementType)&stu4);
    // p.SetPrint(Print);
    // p.show();
    // a.UpdateByIndex(2,(ElementType)&stu6);
    // a.show();
    // a.UpdateByElement((ElementType)&stu5,(ElementType)&stu6);
    // a.show();
    a.RemoveByElement(stu1);
c = a;
    // if(a.ContnsContains(b))
    // {
    //     std::cout<<"Okkk\n";
    // }
    // a[1] = stu9;
    // a.show();
    //c = a.FdIntrSctn(b);
    //a.Sort();
    //c.show();
    //a.show();
    // c = a.Merge(b);
    // c.show();
    // a.Sort();
    // a.show();
    //a.Duplicate();

    // c = a.FindUnionSet(b);
    // c.show();
    // size_t d = b.BinarySearch((ElementType)&stu8);
    // std::cout<<d<<std::endl;



    //a.show();
    
    return 0;
}